﻿@* 
Project: Aguafrommars/TheIdServer
Copyright (c) 2022 @Olivier Lefebvre
*@
@page
@inject IViewLocalizer Localizer
@model EnableAuthenticatorModel
@{
    ViewData["Title"] = Localizer["Configure authenticator app"];
    ViewData["ActivePage"] = ManageNavPages.TwoFactorAuthentication;
}

<partial name="_StatusMessage" for="StatusMessage" />
<h4>@ViewData["Title"]</h4>
<div>
    <p>@Localizer["To use an authenticator app go through the following steps:"]</p>
    <ol class="list">
        <li>
            <p>
                @Localizer["Download a two-factor authenticator app like Microsoft Authenticator for <a href=\"{0}\">Windows Phone</a>, <a href=\"{1}\">Android</a> and <a href=\"{2}\">iOS</a> or Google Authenticator for <a href=\"{3}\">Android</a> and <a href=\"{4}\">iOS</a>.",
                "https://go.microsoft.com/fwlink/?Linkid=825071",
                "https://go.microsoft.com/fwlink/?Linkid=825072",
                "https://go.microsoft.com/fwlink/?Linkid=825073",
                "https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2&amp;hl=en",
                "https://itunes.apple.com/us/app/google-authenticator/id388497605?mt=8"]
            </p>
        </li>
        <li>
            <p>
                @Localizer["Scan the QR Code or enter this key <kbd>{0}</kbd> into your two factor authenticator app. Spaces and casing do not matter.", @Model.SharedKey]
            </p>
            <div id="qrCode"></div>
            <div id="qrCodeData" data-url="@Html.Raw(Model.AuthenticatorUri)"></div>
        </li>
        <li>
            <p>
                @Localizer["Once you have scanned the QR code or input the key above, your two factor authentication app will provide youm with a unique code.Enter the code in the confirmation box below."]
            </p>
            <div class="row">
                <div class="col-md-6">
                    <form method="post">
                        <div class="form-floating mb-2">
                            <input asp-for="Input.Code" class="form-control" autocomplete="off" />
                            <label asp-for="Input.Code" class="control-label form-label">@Localizer["Verification Code"]</label>
                            <span asp-validation-for="Input.Code" class="text-danger"></span>
                        </div>
                        <button type="submit" class="w-100 btn btn-lg btn-primary">@Localizer["Verify"]</button>
                        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
                    </form>
                </div>
            </div>
        </li>
    </ol>
</div>

@section Scripts {
    <partial name="_ValidationScriptsPartial" />

    <script type="text/javascript" src="~/lib/qrcode.js"></script>
    <script type="text/javascript">
        new QRCode(document.getElementById("qrCode"),
            {
                text: "@Html.Raw(Model.AuthenticatorUri)",
                width: 150,
                height: 150
            });
    </script>
}
